using System;
using System.Drawing;

namespace PacSnake
{
    /// <summary>
    /// Enum voor every possible item in a level
    /// </summary>
    public enum ItemType
    {
        CornerUpperLeft,
        CornerUpperRight,
        CornerLowerLeft,
        CornerLowerRight,
        CornerTDown,
        CornerTUp,
        CornerTLeft,
        CornerTRight,
        CornerCross,
        StraightHorizontal,
        StraightVertical,
        Space,
        Food
    }
    

    /// <summary>
    /// An Item is an object in the game. A certain wall, food, etc.. This
    /// class holds all the properties that belong to an item.
    /// </summary>
    public class Item
    {
        // Item is food for the snake
        private bool isCandy = false;
        
        // Checks if a piece of food is eaten
        private bool candyEaten = false;
        
        // Checks if the item is a wall, default to true
        private bool isWall = true;
        
        // The item type
        private ItemType itemType;
        
        // rectangle that represents the position of the item
        private Rectangle rect;
        
        private const int ITEM_SIZE = 20;


        #region Constructor
        
        /// <summary>
        /// Constructor: Sets the item's properties
        /// </summary>
        /// <param name="item">Char representation of the item</param>
        /// <param name="x">X-coordinate of the item</param>
        /// <param name="y">Y-coordinate of the item</param>
        /// <param name="mazeOffsetX">X-offset of the level</param>
        /// <param name="mazeOffsetY">Y-offset of the level</param>
        public Item(char item, int x, int y, int mazeOffsetX, int mazeOffsetY)
        {
            // Calculate the position if the item
            int xPos = mazeOffsetX + x * ITEM_SIZE;
            int yPos = mazeOffsetY + y * ITEM_SIZE;

            // Create the item's rectangle
            rect = new Rectangle(xPos, yPos, ITEM_SIZE, ITEM_SIZE);

            // Sets whether the item is empty (free space in the maze) or not
            switch(item) 
            {
                case 'Q':
                    itemType = ItemType.CornerUpperLeft;
                    break;
                case 'P':
                    itemType = ItemType.CornerUpperRight;
                    break;
                case 'Z':
                    itemType = ItemType.CornerLowerLeft;
                    break;
                case 'M':
                    itemType = ItemType.CornerLowerRight;
                    break;
                case 'A':
                    itemType = ItemType.CornerTRight;
                    break;
                case 'L':
                    itemType = ItemType.CornerTLeft;
                    break;
                case 'T':
                    itemType = ItemType.CornerTDown;
                    break;
                case 'V':
                    itemType = ItemType.CornerTUp;
                    break;
                case 'G':
                    itemType = ItemType.CornerCross;
                    break;
                case '-':
                    itemType = ItemType.StraightHorizontal;
                    break;
                case '[':
                    itemType = ItemType.StraightVertical;
                    break;
                case 'F':
                    isCandy = true;
                    isWall = false;
                    break;
                default:
                    isWall = false;
                    break;
            }
        }
        
        #endregion

        #region Properties

        public Rectangle Rect
        {
            get { return rect; }
        }

        public bool IsWall
        {
            get { return isWall; }
        }

        public bool IsCandy
        {
            get { return isCandy; }
        }

        public bool IsCandyEaten
        {
            get { return candyEaten; }
            set { candyEaten = value; }
        }
        
        public ItemType ItemType
        {
            get { return itemType; }
        }
        
        #endregion
    }
}
